package com.xcc.dataStructures.demo05_recursion;

/**
 *简单的递归调用
 *
 * @author xiaocheng
 * @date 2020/11/30 9:43
 */
public class TestRecursion {

    public static void main(String[] args) {
        test(4);
        //阶乘 factorial
        System.out.println(factorial(3));
    }

    private static int factorial(int n) {
        if (n > 1 ) {
            return n * factorial(n-1);
        }
        return n;
    }

    public static void test(int n) {
        if (n > 2) {
            test(n - 1);
        }
        System.out.println("n = " + n);
    }

}
